package com.ihr360.rest.service.fallback;


import com.ihr360.rest.service.MessageService;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class MessageServiceFallback implements MessageService {

    @Override
    public String message(@PathVariable(name = "locale") String locale, @PathVariable(name = "messageId") String messageId) {
        return messageId;
    }

    @Override
    public List<String> messages(@PathVariable(name = "locale") String locale, @RequestBody String[] messageIds) {
        return Arrays.asList(messageIds);
    }

    @Override
    public Map<String, String> messagesMap(@PathVariable(name = "locale") String locale, @RequestBody String[] messageIds) {
        Map<String, String> map = new HashMap<>();
        for (String messageId : messageIds) {
            map.put(messageId, messageId);
        }
        return map;
    }

    @Override
    public Map<String, String> messagesMap(@PathVariable(name = "locale") String locale, @RequestBody Map<String, Object[]> messageMap) {
        Map<String, String> map = new HashMap<>();
        for (String messageId : messageMap.keySet()) {
            map.put(messageId, messageId);
        }
        return map;
    }

    @Override
    public Map<String, List<String>> messagesMap(@RequestBody Map<String, Object[]> messageMap) {
        Map<String, List<String>> map = new HashMap<>();
        for (String messageId : messageMap.keySet()) {
            List<String> messageList = new ArrayList<>();
            messageList.add(messageId);
            map.put(messageId, messageList);
        }
        return map;
    }
}